<template>
  <div class="user">
    <el-card class="box-card" v-if="status === 'index'">
      <el-row>
        <el-input
          v-model="searchParams.user_id"
          placeholder="请输入用户ID"
          clearable
          style="width:200px"
          size="mini"
        ></el-input>
        <el-input
          v-model="searchParams.challenge_box_id"
          placeholder="请输入擂台ID"
          clearable
          style="width:200px"
          size="mini"
        ></el-input>
        <el-input
          v-model="searchParams.boxs"
          placeholder="请输入箱数"
          clearable
          style="width:200px"
          size="mini"
        ></el-input>
        <el-select
          v-model="searchParams.is_finish"
          placeholder="请选择状态"
          clearable
          :style="{ width: '150px' }"
          size="mini"
        >
          <el-option
            v-for="item in statusData"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          ></el-option>
        </el-select>
        <el-button
          type="primary"
          size="mini"
          @click="getData"
          v-if="has('challengeUserBoxBags/index')"
        >搜索
        </el-button
        >
        <el-button
          type="info"
          size="mini"
          @click="reset"
          v-if="has('challengeUserBoxBags/index')"
        >重置
        </el-button
        >
      </el-row>
      <el-table
        :data="data.data"
        v-loading="table_loading"
        style="width: 100%;margin:10px auto"
        size="mini"
        :header-cell-style="{ background: '#f3f8fe', color: '#333' }"
      >
        <el-table-column
          prop="id"
          label="ID"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="id"
          label="用户信息"
          align="center"
        >
          <template slot-scope="scope">
            <div style="display: flex;align-items: center;">
              <img
                :src="scope.row.avatar"
                :style="{ width: '50px', height: '50px', borderRadius: '5px' }"
                @click="bigImage(scope.row.avatar)"
              />
              <div>
                <div>{{ scope.row.name }}</div>
                <div>ID:{{ scope.row.user_id }}</div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="id" label="擂台信息" align="center">
          <template slot-scope="scope">
            <div style="display: flex;align-items: center;">
              <img
                :src="scope.row.box_image"
                :style="{ width: '50px', height: '50px', borderRadius: '5px' }"
                @click="bigImage(scope.row.box_image)"
              />
              <div>
                <div>{{ scope.row.box_name }}</div>
                <div>ID:{{ scope.row.challenge_box_id }}</div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="parent_id"
          label="父ID"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="boxs"
          label="箱数"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="type_name"
          label="类型"
          align="center"
        ></el-table-column>
        <el-table-column prop="id" label="开启信息" align="center">
          <template slot-scope="scope">
            <div style="display: flex;align-items: center;">
              <img
                :src="scope.row.draw_image"
                :style="{ width: '50px', height: '50px', borderRadius: '5px' }"
                @click="bigImage(scope.row.draw_image)"
              />
              <div>
                <div>{{ scope.row.draw_name }}</div>
                <div>兑换价:{{ scope.row.draw_price }}</div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="is_finish" label="开启" align="center">
          <template slot-scope="scope">
            <span
              :style="statusArr[scope.row.status - 1].style"><b>{{ statusArr[scope.row.status - 1].title }}</b></span>
          </template>
        </el-table-column>
        <el-table-column
          prop="created_at"
          label="创建时间"
          align="center"
        ></el-table-column>
<!--        <el-table-column fixed="right" label="操作" align="center" width="220">-->
<!--          <template slot-scope="scope">-->
<!--            <el-button-->
<!--              type="danger"-->
<!--              size="mini"-->
<!--              @click="del(scope.row.id, scope.$index)"-->
<!--              v-if="has('wealRooms/destroy')"-->
<!--            >删除-->
<!--            </el-button-->
<!--            >-->
<!--          </template>-->
<!--        </el-table-column>-->
      </el-table>
      <el-pagination
        background
        style="text-align:center;margin:20px 0;"
        :current-page="searchParams.page"
        :page-sizes="pageSizes"
        layout="total,prev, pager, next,sizes"
        :total="data.total"
        @size-change="changeSize"
        @current-change="changePage"
      ></el-pagination>
    </el-card>

    <el-card v-if="status === 'add'">
      <div slot="header">
        <el-page-header @back="back()" content="官方福利屋添加"></el-page-header>
      </div>
      <el-form
        ref="form"
        :rules="rules"
        :model="editParams"
        label-width="120px"
      >
        <el-form-item label="福利屋名称" prop="name">
          <el-input v-model="editParams.name" style="width: 300px;"></el-input>
        </el-form-item>

        <el-form-item label="口令" prop="word_command">
          <el-input v-model="editParams.word_command" style="width: 300px;"></el-input>
        </el-form-item>

        <el-form-item label="密码" prop="room_password">
          <el-input v-model="editParams.room_password" style="width: 300px;"></el-input>
        </el-form-item>


        <el-form-item label="指定消费时间段" prop="times">
          <el-date-picker
            v-model="editParams.start_at"
            type="datetime"
            placeholder="选择指定开始时间"
            :picker-options="pickerOptions"
            size="max"
          ></el-date-picker>
        </el-form-item>

        <el-form-item label="指定消费金额" prop="amount">
          <el-input v-model="editParams.amount" style="width: 300px;"></el-input>
        </el-form-item>
        <el-form-item label="开赏时间" prop="begin_reward_at">
          <el-date-picker
            v-model="editParams.begin_reward_at"
            type="datetime"
            placeholder="开赏时间"
            :picker-options="pickerOptions"
            size="max"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="开赏人数" prop="begin_reward_num">
          <el-input v-model="editParams.begin_reward_num" style="width: 300px;"></el-input>
        </el-form-item>
        <el-form-item label="活动介绍" prop="content">
          <Editor v-model="editParams.content"></Editor>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            @click="submit('form', 1)"
            v-if="has('wealRooms/store')"
          >保 存
          </el-button
          >
          <el-button type="info" @click="back()" v-if="has('blindBox/store')"
          >取 消
          </el-button
          >
        </el-form-item>
      </el-form>
    </el-card>

    <el-card v-if="status === 'edit'">
      <div slot="header">
        <el-page-header @back="back()" content="编辑盲盒"></el-page-header>
      </div>
      <el-form
        ref="form"
        :rules="rules"
        :model="editParams"
        label-width="120px"
      >
        <el-form-item label="盲盒名称" prop="name">
          <el-input v-model="editParams.name" style="width: 300px;"></el-input>
        </el-form-item>
        <el-form-item label="盲盒类型" prop="cat_id">
          <el-select
            v-model="editParams.cat_id"
            placeholder="请选择盲盒类型"
            clearable
          >
            <el-option
              v-for="item in catData"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="单抽价格" prop="price">
          <el-input v-model="editParams.price" style="width: 300px;"></el-input>
        </el-form-item>
        <el-form-item label="三连抽价格" prop="three_price">
          <el-input
            v-model="editParams.three_price"
            style="width: 300px;"
          ></el-input>
        </el-form-item>
        <el-form-item label="五连抽价格" prop="five_price">
          <el-input
            v-model="editParams.five_price"
            style="width: 300px;"
          ></el-input>
        </el-form-item>
        <el-form-item label="临界值" prop="income_value">
          <el-input
            v-model="editParams.income_value"
            style="width: 300px;"
          ></el-input>
        </el-form-item>
        <el-form-item label="临界商品id" prop="income_id">
          <el-input
            v-model="editParams.income_id"
            style="width: 300px;"
          ></el-input>
        </el-form-item>
        <el-form-item label="图片" prop="image">
          <el-button size="mini" type="primary" @click="openImage(2, false, {})"
          >选择商品库
          </el-button
          >
          <div>
            <el-image
              v-if="editParams.image"
              :src="editParams.image"
              :preview-src-list="[editParams.image]"
              style="height: 200px"
              fit="contain"
            >
            </el-image>
          </div>
        </el-form-item>

        <el-form-item label="概率" prop="probability">
          <div v-for="(item, index) in editParams.probability" :key="index">
            <div>
              <el-input v-model="item.value" style="width: 300px;" readonly>
                <template slot="prepend" v-if="item.level_id == 1"
                >尊贵 :
                </template
                >
                <template slot="prepend" v-if="item.level_id == 2"
                >稀有 :
                </template
                >
                <template slot="prepend" v-if="item.level_id == 3"
                >史诗 :
                </template
                >
                <template slot="prepend" v-if="item.level_id == 4"
                >传说 :
                </template
                >
                <template slot="append">%</template>
              </el-input>
            </div>
          </div>
        </el-form-item>

        <el-form-item label="排序" prop="sort">
          <el-input v-model="editParams.sort" style="width: 300px;"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            @click="submit('form', 2)"
            v-if="has('blindBox/store')"
          >保 存
          </el-button
          >
          <el-button type="info" @click="back()" v-if="has('blindBox/store')"
          >取 消
          </el-button
          >
        </el-form-item>
      </el-form>
    </el-card>

    <el-card v-if="status === 'prize'">
      <div slot="header">
        <el-page-header @back="back()" content="赏品列表"></el-page-header>
      </div>
      <el-row>
        <el-input
          v-model="prizeSearchParams.name"
          placeholder="请输入赏品名称"
          clearable
          style="width:200px"
          size="mini"
        ></el-input>
        <el-select
          v-model="prizeSearchParams.levelId"
          style="width:200px"
          clearable
          size="mini"
          placeholder="请选择赏品等级"
        >
          <el-option
            v-for="item in levelData"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          ></el-option
          >
        </el-select>

        <el-button
          type="primary"
          size="mini"
          @click="getPrize"
          v-if="has('wealRoomsPrizes/index')"
        >搜索
        </el-button
        >
        <el-button
          type="primary"
          @click="addPrize()"
          size="mini"
          v-if="has('wealRoomsPrizes/store')"
        >添加
        </el-button
        >
      </el-row>
      <el-table
        :data="prizeData.data"
        v-loading="prizeTableLoading"
        style="width: 100%;margin:10px auto"
        size="mini"
        :header-cell-style="{ background: '#f3f8fe', color: '#333' }"
      >
        <el-table-column
          fixed
          prop="id"
          label="赏品信息"
          align="center"
          width="250px"
        >
          <template slot-scope="scope">
            <div style="display: flex;align-items: center;">
              <img
                :src="scope.row.image"
                :style="{
                  width: '50px',
                  height: '50px',
                  borderRadius: '5px',
                  marginRight: '10px'
                }"
                @click="bigImage(scope.row.image)"
              />
              <div>
                <div>赏品ID：{{ scope.row.id }}</div>
                <div>{{ scope.row.name }}</div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="level_name" label="等级" align="center">
          <template slot-scope="scope">
            <span
              :style="{
                backgroundColor: scope.row.level_color,
                color: '#fff',
                padding: '10px',
                height: '20px',
                lineHeight: '20px',
                textAlign: 'center',
                width: '100px',
                borderRadius: '10px'
              }"
            >
              {{ scope.row.level_name }}
            </span>
          </template>
        </el-table-column>
        <el-table-column
          prop="price"
          label="价格"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="recovery_price"
          label="兑换价"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="created_at"
          label="创建时间"
          align="center"
        ></el-table-column>
        <el-table-column fixed="right" label="操作" align="center" width="200">
          <template slot-scope="scope">
            <!-- <el-button
              type="primary"
              size="mini"
              @click="editPrize(scope.row.id)"
              v-if="has('blindBox/show')"
              >编辑</el-button
            > -->
            <el-button
              type="danger"
              size="mini"
              @click="delPrize(scope.row.id, scope.$index)"
              v-if="has('wealRoomsPrizes/destroy')"
            >删除
            </el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        style="text-align:center;margin:20px 0;"
        :current-page="prizeSearchParams.page"
        :page-sizes="pageSizes"
        layout="total,prev, pager, next,sizes"
        :total="prizeData.total"
        @size-change="changePrizeSize"
        @current-change="changePrizePage"
      ></el-pagination>
    </el-card>

    <el-card v-show="status === 'log'">
      <div slot="header">
        <el-page-header
          @back="back()"
          @click="getLog(scope.row.id)"
          :content="'开奖记录:' + logTitle + ':' + logSearchParams.blind_box_id"
        ></el-page-header>
      </div>
      <el-row>
        <el-input
          v-model="logSearchParams.userId"
          placeholder="请输入用户id"
          clearable
          style="width:200px"
          size="mini"
        ></el-input>
        <el-select
          v-model="logSearchParams.levelId"
          style="width:200px"
          clearable
          size="mini"
          placeholder="请选择赏品等级"
        >
          <el-option
            v-for="item in levelData"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          ></el-option
          >
        </el-select>
        <el-button
          type="primary"
          size="mini"
          @click="getLog()"
          v-if="has('wealRoomsOrdersPrizes/show')"
        >搜索
        </el-button>
      </el-row>
      <el-table
        :data="logData.data"
        v-loading="logTableLoading"
        style="width: 100%;margin:10px auto"
        size="mini"
        :header-cell-style="{ background: '#f3f8fe', color: '#333' }"
      >
        <el-table-column
          label="用户信息"
          align="center"
          prop="user_id"
          width="150px"
        >
          <template slot-scope="scope">
            <div style="display: flex;">
              <el-image
                :src="scope.row.avatar"
                :preview-src-list="[scope.row.avatar]"
                fit="contain"
                :style="{
                  width: '50px',
                  height: '50px',
                  borderRadius: '5px',
                  marginRight: '10px',
                  alignItems: 'center'
                }"
              ></el-image>
              <div
                style="display: flex;flex-direction: column;justify-content: space-between;"
              >
                <span>{{ scope.row.nickname }}</span>
                <span>ID:{{ scope.row.user_id }}</span>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="赏品信息" align="center" width="300px">
          <template slot-scope="scope">
            <div style="display: flex;align-items: center;">
              <el-image
                :src="scope.row.weal_rooms_prizes_image"
                :preview-src-list="[scope.row.weal_rooms_prizes_image]"
                :style="{
                  width: '50px',
                  height: '50px',
                  marginRight: '10px'
                }"
              ></el-image>
              <div>
                <div>{{ scope.row.weal_rooms_prizes_name }}</div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="level_name" label="等级" align="center">
          <template slot-scope="scope">
            <span
              :style="{
                backgroundColor: scope.row.level_color,
                color: '#fff',
                padding: '10px',
                height: '20px',
                lineHeight: '20px',
                textAlign: 'center',
                width: '100px',
                borderRadius: '10px'
              }"
            >
              {{ scope.row.level_name }}
            </span>
          </template>
        </el-table-column>
        <el-table-column
          prop="num"
          label="数量"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="price"
          label="价值"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="recovery_price"
          label="兑换价"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="created_at"
          label="中奖时间"
          align="center"
        ></el-table-column>
      </el-table>
      <el-pagination
        background
        style="text-align:center;margin:20px 0;"
        :current-page="logSearchParams.page"
        :page-sizes="pageSizes"
        layout="total,prev, pager, next,sizes"
        :total="logData.total"
        @size-change="changeLogSize"
        @current-change="changeLogPage"
      ></el-pagination>
    </el-card>
    <el-card v-show="status === 'participationLog'">
      <div slot="header">
        <el-page-header
          @back="back()"
          :content="'参与者记录:' + logTitle + ':' + cySearchParams.blind_box_id"
        ></el-page-header>
      </div>
      <el-row>
        <el-input
          v-model="cySearchParams.userId"
          placeholder="请输入用户id"
          clearable
          style="width:200px"
          size="mini"
        ></el-input>
        <el-select
          v-model="cySearchParams.levelId"
          style="width:200px"
          clearable
          size="mini"
          placeholder="请选择赏品等级"
        >
          <el-option
            v-for="item in levelData"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          ></el-option
          >
        </el-select>
        <el-button
          type="primary"
          size="mini"
          @click="getParticipation()"
          v-if="has('wealRoomsOrdersPrizes/show')"
        >搜索
        </el-button>
      </el-row>
      <el-table
        :data="cyData.data"
        v-loading="logTableLoading"
        style="width: 100%;margin:10px auto"
        size="mini"
        :header-cell-style="{ background: '#f3f8fe', color: '#333' }"
      >
        <el-table-column
          label="用户信息"
          align="center"
          prop="user_id"
          width="150px"
        >
          <template slot-scope="scope">
            <div style="display: flex;">
              <el-image
                :src="scope.row.avatar"
                :preview-src-list="[scope.row.avatar]"
                fit="contain"
                :style="{
                  width: '50px',
                  height: '50px',
                  borderRadius: '5px',
                  marginRight: '10px',
                  alignItems: 'center'
                }"
              ></el-image>
              <div
                style="display: flex;flex-direction: column;justify-content: space-between;"
              >
                <span>{{ scope.row.nickname }}</span>
                <span>ID:{{ scope.row.user_id }}</span>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="nickname"
          label="昵称"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="mobile"
          label="手机号码"
          align="center"
        ></el-table-column>

        <el-table-column
          label="上级用户信息"
          align="center"
          prop="user_id"
          width="150px"
        >
          <template slot-scope="scope">
            <div style="display: flex;">
              <el-image
                :src="scope.row.parent_avatar"
                :preview-src-list="[scope.row.parent_avatar]"
                fit="contain"
                :style="{
                  width: '50px',
                  height: '50px',
                  borderRadius: '5px',
                  marginRight: '10px',
                  alignItems: 'center'
                }"
              ></el-image>
              <div
                style="display: flex;flex-direction: column;justify-content: space-between;"
              >
                <span>{{ scope.row.parent_nickname }}</span>
                <span>ID:{{ scope.row.parent_user_id }}</span>
              </div>
            </div>
          </template>
        </el-table-column>

        <el-table-column fixed="right" label="操作" align="center" width="220" >
          <template slot-scope="scope" v-if="scope.row.is_finish == 1">
            <el-button
              type="danger"
              size="mini"
              @click="delParticipations(scope.row.id, scope.$index)"
              v-if="has('wealRoomsParticipations/destroy')"
            >删除
            </el-button
            >
          </template>
        </el-table-column>

      </el-table>
      <el-pagination
        background
        style="text-align:center;margin:20px 0;"
        :current-page="logSearchParams.page"
        :page-sizes="pageSizes"
        layout="total,prev, pager, next,sizes"
        :total="cyData.total"
        @size-change="changecySize"
        @current-change="changecyPage"
      ></el-pagination>
    </el-card>
    <el-dialog
      title="确定赏品"
      :visible.sync="prizeStatus"
      width="80%"
      :close-on-click-modal="false"
    >
      <el-row>
        <el-button
          type="primary"
          @click="selectPrize()"
          size="mini"
          v-if="has('wealRoomsPrizes/store')"
        >选择赏品
        </el-button
        >
      </el-row>
      <el-table :data="submitPrizeData" v-if="submitPrizeData.length > 0">
        <el-table-column
          fixed
          prop="id"
          label="赏品信息"
          align="center"
          width="160px"
        >
          <template slot-scope="scope">
            <div style="display: flex;align-items: center;">
              <img
                :src="scope.row.image"
                :style="{
                  width: '50px',
                  height: '50px',
                  borderRadius: '5px',
                  marginRight: '10px'
                }"
                @click="bigImage(scope.row.image)"
              />
              <div>
                <div>{{ scope.row.name }}</div>
                <div>{{ scope.row.id }}</div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="price" label="等级" align="center">
          <template slot-scope="scope">
            <span
              :style="{
                backgroundColor: scope.row.level.color,
                color: '#fff',
                padding: '10px',
                height: '20px',
                lineHeight: '20px',
                textAlign: 'center',
                width: '100px',
                borderRadius: '10px'
              }"
            >
              {{ scope.row.level.name }}
            </span>
          </template>
        </el-table-column>

        <el-table-column
          prop="price"
          label="价格"
          align="center"
        ></el-table-column>
        <el-table-column prop="recovery_price" label="兑换价" align="center">
          <template slot-scope="scope">
            <el-input
              v-model="scope.row.recovery_price"
              placeholder="请输入兑换价"
            ></el-input>
          </template>
        </el-table-column>
        <el-table-column
          prop="created_at"
          label="时间"
          align="center"
        ></el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="addPrizeSubmit">保 存</el-button>
      </div>
    </el-dialog>

    <el-dialog
      title="选择赏品"
      :visible.sync="addPrizeStatus"
      :close-on-click-modal="false"
    >
      <el-row>
        <el-select
          v-model="selectPrizeParams.levelId"
          style="width:200px"
          clearable
          size="mini"
          placeholder="请选择赏品等级"
        >
          <el-option
            v-for="item in levelData"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          ></el-option
          >
        </el-select>
        <el-button type="primary" @click="getSelectPrize()" size="mini"
        >搜索
        </el-button
        >
      </el-row>
      <el-table
        :data="selectPrizeData.data"
        @selection-change="changePrize"
        v-loading="addPrizeLoading"
      >
        <el-table-column type="selection" width="55"></el-table-column>

        <el-table-column
          fixed
          prop="id"
          label="赏品信息"
          align="center"
          width="160px"
        >
          <template slot-scope="scope">
            <div style="display: flex;align-items: center;">
              <img
                :src="scope.row.image"
                :style="{
                  width: '50px',
                  height: '50px',
                  borderRadius: '5px',
                  marginRight: '10px'
                }"
                @click="bigImage(scope.row.image)"
              />
              <div>
                <div>{{ scope.row.name }}</div>
                <div>{{ scope.row.id }}</div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="price" label="等级" align="center">
          <template slot-scope="scope">
            <span
              :style="{
                backgroundColor: scope.row.level.color,
                color: '#fff',
                padding: '10px',
                height: '20px',
                lineHeight: '20px',
                textAlign: 'center',
                width: '100px',
                borderRadius: '10px'
              }"
            >
              {{ scope.row.level.name }}
            </span>
          </template>
        </el-table-column>
        <el-table-column
          prop="price"
          label="价格"
          align="center"
        ></el-table-column>

        <el-table-column
          prop="created_at"
          label="时间"
          align="center"
        ></el-table-column>
      </el-table>

      <el-pagination
        background
        style="text-align:center;margin:20px 0;"
        :current-page="selectPrizeParams.page"
        :page-sizes="pageSizes"
        layout="total,prev, pager, next,sizes"
        :total="selectPrizeData.total"
        @size-change="changeSelectPrizeSize"
        @current-change="changeSelectPrizePage"
      ></el-pagination>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="selectPrizeSubmit">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog title="编辑赏品" :visible.sync="editPrizeStatus">
      <el-form :model="editPrizeParams">
        <el-form-item label="赏品信息" label-width="100px">
          <div style="display: flex;align-items: center;">
            <img
              :src="editPrizeParams.goods.image"
              :style="{
                width: '50px',
                height: '50px',
                borderRadius: '5px',
                marginRight: '10px'
              }"
              @click="bigImage(editPrizeParams.goods.image)"
            />
            <div>
              <div>{{ editPrizeParams.goods.name }}</div>
              <div>赏品ID：{{ editPrizeParams.id }}</div>
            </div>
          </div>
        </el-form-item>

        <el-form-item label="等级" label-width="100px">
          <el-select
            v-model="editPrizeParams.level_id"
            disabled
            style="width:200px"
          >
            <el-option
              v-for="item in levelData"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="价格" label-width="100px">
          <el-input
            v-model="editPrizeParams.price"
            autocomplete="off"
            style="width:200px"
            disabled
          ></el-input>
        </el-form-item>
        <el-form-item label="兑换价" label-width="100px">
          <el-input
            v-model="editPrizeParams.recovery_price"
            autocomplete="off"
            style="width:200px"
          ></el-input>
        </el-form-item>
        <el-form-item label="概率" label-width="100px">
          <el-input
            v-model="editPrizeParams.probability"
            autocomplete="off"
            style="width:200px"
          >
            <template slot="append">%</template>
          </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="editPrizeSubmit">保存</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="showRenwal" style="width: 1200px; margin: 0 auto" >
      <template v-slot:default>
        <div>
          <el-form>
            <el-form-item label="续期天数">
              <el-input size="small" v-model="day" style="width: 300px;"></el-input>

            </el-form-item>
          </el-form>
       </div>
      </template>
      <template v-slot:footer>
        <el-button type="primary" @click="changeRenewal">确定</el-button>
      </template>
    </el-dialog>

    <SimpleImageUpload
      :cardStatus="cardStatus"
      :imageFormatArr="imageFormatArr"
      :imageData="imageData"
      :imageLoading="imageLoading"
      :uploadImageAction="uploadImageUrl"
      :multiple="multiple"
      @uploadImageSuccess="uploadFileSuccess"
      @uploadImageBefore="uploadImageBefore"
      @changeImageSize="changeImageSize"
      @changeImagePage="changeImagePage"
      @changeImageFormat="changeImageFormat"
      @choiceImageConfirm="choiceImageConfirm"
      @closeImage="closeImage"
      @getImages="getImages"
    ></SimpleImageUpload>
  </div>
</template>

<script>
import api from "../../api/api.js";
import Editor from "@/components/Editer/index.vue";
import SimpleImageUpload from "@/components/SimpleImageUpload/index.vue";

export default {
  name: "user",
  components: {
    SimpleImageUpload,
    Editor
  },
  data() {
    return {
      status: "index", // 页面控制
      data: {data: []}, // 表格诗句
      levelData: [],
      table_loading: true, // 表格加载中
      loading: false, //全局加载中
      pageSizes: [10, 20, 50, 100, 200, 500, 800, 1000, 2000], // 每页条数默认10
      pickerOptions: {
        shortcuts: [
          {
            text: "今天",
            onClick(picker) {
              picker.$emit("pick", new Date());
            }
          },
          {
            text: "昨天",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit("pick", date);
            }
          },
          {
            text: "一周前",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", date);
            }
          }
        ]
      },
      statusArr: [
        {id: 0, title: "否", style: {color: "red"}},
        {id: 1, title: "是", style: {color: "green"}},
        {id: 2, title: "兑换", style: {color: "green"}}
      ],
      jinduArr: [
        {id: 0, title: "进行中...", style: {color: "green"}},
        {id: 1, title: "已开奖", style: {color: "red"}}
      ],
      statusData: [
        {id: 1, name: "未开"},
        {id: 2, name: "已开"},
        {id: 3, name: "已兑换"},
      ],
      officialData: [
        {id: 0, name: "否"},
        {id: 1, name: "是"},
      ],
      searchParams: {
        // 搜索参数
        page: 1,
        limit: 10,
        name: ""
      },
      editParams: {
        name: "",
        cat_id: "",
        image: "",
        sort: "",
        price: "",
        three_price: "",
        five_price: "",
        probability: [
          {name: "尊贵", level_id: 1},
          {name: "稀有", level_id: 2},
          {name: "史诗", level_id: 3},
          {name: "传说", level_id: 4}
        ]
      },
      catData: [
        {id: 1, name: "热门盲盒"},
        {id: 2, name: "快乐加倍"}
      ],
      renewalData: [
        {id: 0, name: "否"},
        {id: 1, name: "是"}
      ],

      rules: {
        // 验证规则
        name: [{required: true, message: "请输入福利屋名称", trigger: "blur"}],
        amount: [{required: true, message: "请选择指定消费金额", trigger: "blur"}],
        start_at: [{required: true, message: "请选择指定消费开始时间", trigger: "blur"}],
        begin_reward_num: [{required: true, message: "请输入开赏人数", trigger: "blur"}],
        begin_reward_at: [{required: true, message: "请选择开赏时间", trigger: "blur"}],
      },

      activeValue: 1,
      inactiveValue: 0,

      cardStatus: false,
      imageFormatArr: [
        {id: "", title: "全部"},
        {id: 1, title: "商品图片"},
        {id: 2, title: "商品详情图"},
        {id: 3, title: "banner"},
        {id: 4, title: "活动"},
        {id: 5, title: "盲盒"}
      ],
      imageParams: {
        format: "",
        page: 1
      },
      imageData: {},
      imageLoading: false,
      uploadImageUrl: "/admin/common/upload?format=5",
      multiple: false,
      scene: 1, // 打开组件场景
      extra: {},

      prizeData: {data: []},
      prizeSearchParams: {
        wealRoomsPrizesId: "",
        name: "",
        levelId: "",
        page: 1,
        limit: 10
      },
      prizeTableLoading: true, // 赏品表格加载中
      prizeStatus: false,
      submitPrizeData: [],
      selectPrizeData: {data: []},
      addPrizeStatus: false,
      addPrizeData: [],
      editPrizeStatus: false,
      editPrizeParams: {
        id: "",
        goods: {}
      },
      addPrizeLoading: true,
      selectPrizeParams: {levelId: "", page: 1, limit: 20},
      logData: {data: []},
      cyData: {data: []},
      logSearchParams: {
        // 搜索参数
        userId: "",
        levelId: "",
        page: 1,
        limit: 10,
        blind_box_id: "",
        startTime: "",
        endTime: ""
      },
     cySearchParams: {
        // 搜索参数
        userId: "",
        levelId: "",
        page: 1,
        limit: 10,
        blind_box_id: "",
        startTime: "",
        endTime: ""
      },
      logTableLoading: true,
      logTitle: "",
      showRenwal: false,
      renwal: {},
      day: 1,
    };
  },
  created() {
    this.getData();
    this.getLevel();
  },

  methods: {
    queryParticipation(id) {
      this.getParticipation(id)
    },
    showRenwalDialog(e) {
      this.renwal = e
      this.showRenwal = true
    },
    participation(row){
      this.cySearchParams.blind_box_id = row.id;
      this.logTitle = row.name;
      this.status = "participationLog";
      this.getParticipation(row.id)
    },
    getParticipation(id){
      this.logTableLoading = true;
      api.wealRoomsParticipations
        .index(this.cySearchParams.blind_box_id,{params: this.cySearchParams})
        .then(res => {
          if (res.data.code == 200) {
            this.logTableLoading = false;
            this.cyData = res.data.data;
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    log(row) {
      this.logSearchParams.blind_box_id = row.id;
      this.logTitle = row.name;
      this.status = "log";
      this.getLog(row.id);
    },
    getLog(id) {
      this.logTableLoading = true;
      api.wealRoomsOrdersPrizes
        .show(this.logSearchParams.blind_box_id, {params: this.logSearchParams})
        .then(res => {
          if (res.data.code == 200) {
            this.logTableLoading = false;
            this.logData = res.data.data;
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    editPrizeSubmit() {
      this.load();
      api.blindBoxPrizes
        .edit(this.editPrizeParams.id, this.editPrizeParams)
        .then(res => {
          this.unload();
          if (res.data.code == 200) {
            this.$message.success(res.data.msg);
            this.editPrizeStatus = false;
            this.getPrize();
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    editPrize(id) {
      this.load();
      api.blindBoxPrizes
        .show(id)
        .then(res => {
          this.unload();
          if (res.data.code == 200) {
            this.editPrizeParams = res.data.data;
            this.editPrizeStatus = true;
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    // 最终确定选择赏品
    addPrizeSubmit() {
      if (this.submitPrizeData.length == 0) {
        this.$message.error("请选择赏品");
        return;
      }

      for (var i = 0; i < this.submitPrizeData.length; i++) {
        if (!this.submitPrizeData[i].price) {
          this.$message.error("请输入兑换价");
          return false;
        }
      }

      api.wealRoomsPrizes
        .store({
          wealRoomsPrizesId: this.prizeSearchParams.wealRoomsPrizesId,
          prize: this.submitPrizeData
        })
        .then(res => {
          if (res.data.code == 200) {
            this.prizeStatus = false;
            this.submitPrizeData = [];
            this.getPrize();
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    selectPrizeSubmit() {
      this.submitPrizeData.push(...this.addPrizeData);
      this.addPrizeStatus = false;
      this.addPrizeData = [];
    },
    changePrize(e) {
      // if (!e.length) return
      this.addPrizeData = e;
    },
    getSelectPrize() {
      this.submitPrizeData.push(...this.addPrizeData)
      this.addPrizeData = [];
      this.addPrizeLoading = true;
      api.common
        .getWealPrize({params: this.selectPrizeParams})
        .then(res => {
          if (res.data.code == 200) {
            this.addPrizeLoading = false;
            this.selectPrizeData = res.data.data;
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    selectPrize() {
      this.addPrizeStatus = true;
      this.getSelectPrize();
    },
    // 显示第一个选择赏品框
    addPrize() {
      this.prizeStatus = true;
    },
    prize(id) {
      this.status = "prize";
      this.prizeSearchParams.wealRoomsPrizesId = id;
      this.getPrize();
    },
    getPrize() {
      this.prizeTableLoading = true;
      api.wealRoomsPrizes
        .index({params: this.prizeSearchParams})
        .then(res => {
          this.prizeTableLoading = false;
          if (res.data.code == 200) {
            this.prizeData = res.data.data;
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    changeStatus(e) {
      this.load();
      api.wealRooms
        .status(e.id, {status: e.status})
        .then(res => {
          this.unload();
          if (res.data.code === 200) {
            this.$message.success("保存成功");
            this.init();
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    changeRenewal(e) {
      this.showRenwal = false
      this.load();
      api.wealRooms
        .renewal(this.renwal.id, {is_renewal: this.renwal.is_renewal, day: this.day})
        .then(res => {
          this.unload();
          if (res.data.code === 200) {
            this.$message.success("保存成功");
            this.init();
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    // 组件图片上传成功取消遮罩重新请求数据
    uploadFileSuccess(res) {
      this.unload();
      this.getImages();
      this.$message.success(res.msg);
    },
    // 查看图片
    getImages() {
      this.cardStatus = true;
      this.imageLoading = true;
      api.images
        .index({params: this.imageParams})
        .then(res => {
          this.imageLoading = false;
          if (res.data.code == 200) {
            this.imageData = res.data.data;
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    // 组件确定选择图片
    choiceImageConfirm(choiceImages) {
      if (this.scene == 1) {
        this.editParams.goods_images = this.editParams.goods_images.concat(
          choiceImages
        );
      } else if (this.scene == 2) {
        this.editParams.image = choiceImages[0];
      } else if (this.scene == 3) {
        this.extra.row.image = choiceImages[0];
      } else if (this.scene == 4) {
        var html = "";
        choiceImages.map(item => {
          html += `<div><img src="${item}" /></div>`;
        });
        this.setHtml(html);
        console.log("html:", html);
      }
    },
    // 改变图片组件每页条数时
    changeImageSize(limit) {
      this.imageParams.limit = limit;
      this.getImages();
    },
    // 改变图片组件当前页码时
    changeImagePage(page) {
      this.imageParams.page = page;
      this.getImages();
    },
    // 改变图片组件每页条数时
    changePrizeSize(limit) {
      this.prizeSearchParams.limit = limit;
      this.getPrize();
    },

    // 改变图片组件当前页码时
    changePrizePage(page) {
      this.prizeSearchParams.page = page;
      this.getPrize();
    },
    // changeSelectPrizeSize

    changeSelectPrizeSize(limit) {
      this.selectPrizeParams.limit = limit;
      this.getSelectPrize();
    },
    changeSelectPrizePage(page) {
      this.selectPrizeParams.page = page;
      this.getSelectPrize();
    },

    // 改变图片组件每页条数时
    changeLogSize(limit) {
      this.logSearchParams.limit = limit;
      this.getLog();
    },
    // 改变图片组件当前页码时
    changeLogPage(page) {
      this.logSearchParams.page = page;
      this.getLog();
    },
    // 改变图片组件当前页码时
    changecyPage(page) {
      this.cySearchParams.page = page;
      this.getParticipation();
    },
    // 改变图片组件每页条数时
    changecySize(limit) {
      this.cySearchParams.limit = limit;
      this.getParticipation();
    },
    // 打开组件图片
    openImage(scene, multiple, extra) {
      this.multiple = multiple; // 单选还是多选
      this.scene = scene;
      this.extra = extra; // 额外数据
      this.cardStatus = true;
      this.getImages();
    },
    uploadImageBefore() {
      this.load();
    },
    closeImage() {
      this.cardStatus = false;
    },
    // 重置图片搜索参数
    initImage(type) {
      this.imageParams.format = type;
      this.imageParams.page = 1;
    },
    // 选择类型筛选图片
    changeImageFormat(type) {
      this.initImage(type);
      this.getImages();
    },
    // 查看大图
    bigImage(url) {
      this.$alert("图片", {
        message: "<img  src=" + url + " style='height:200px;width:200px'>",
        dangerouslyUseHTMLString: true
      });
    },
    back() {
      this.status = "index";
      this.logSearchParams.page = 1;
      this.prizeSearchParams.page = 1;
    },
    // 获取所有等级
    getLevel() {
      api.common
        .goodsLevels()
        .then(res => {
          if (res.data.code === 200) {
            this.levelData = res.data.data;
          }
        })
        .catch(error => {
        });
    },

    // 加载中
    load() {
      this.loading = this.$loading({
        lock: true,
        text: "数据加载中",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
    },

    // 取消加载
    unload() {
      this.loading.close();
    },
    // 获取所有数据
    getData() {
      this.table_loading = true;
      api.challengeUserBoxBags
        .index({params: this.searchParams})
        .then(res => {
          if (res.data.code === 200) {
            this.table_loading = false;
            this.data = res.data.data;
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    // 重置搜索参数重新搜索
    reset() {
      this.searchParams.name = "";
      this.searchParams.user_id = "";
      this.searchParams.status = "";
      this.searchParams.is_official = "";
      this.init();
    },
    submit(formName, type) {
      this.$refs[formName].validate((valid, error) => {
        if (valid) {
          // 添加
          this.load();
          if (type === 1) {
            api.wealRooms
              .store(this.editParams)
              .then(res => {
                this.unload();
                if (res.data.code === 200) {
                  this.init();
                }
              })
              .catch(error => {
                console.log(error);
              });
          } else if (type === 2) {
            // 编辑
            api.wealRooms
              .edit(this.editParams.id, this.editParams)
              .then(res => {
                this.unload();
                if (res.data.code === 200) {
                  this.init();
                }
              })
              .catch(error => {
                console.log(error);
              });
          }
        } else {
          this.$message.error(Object.values(error)[0][0].message);
          return false;
        }
      });
    },//delParticipations
    delParticipations(id, index) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        closeOnClickModal: false,
        type: "warning"
      })
        .then(() => {
          this.load();
          api.wealRoomsParticipations
            .del(id)
            .then(res => {
              this.unload();
              if (res.data.code === 200) {
                this.$message({
                  type: "success",
                  message: "踢除成功!"
                });
                this.logData.data.splice(index, 1);
                this.logData.total--;
              }
            })
            .catch(error => {
              console.log(error);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },

    delPrize(id, index) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        closeOnClickModal: false,
        type: "warning"
      })
        .then(() => {
          this.load();
          api.wealRoomsPrizes
            .del(id)
            .then(res => {
              this.unload();
              if (res.data.code === 200) {
                this.$message({
                  type: "success",
                  message: "删除成功!"
                });
                this.prizeData.data.splice(index, 1);
                this.prizeData.total--;
              }
            })
            .catch(error => {
              console.log(error);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    delLog(id) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        closeOnClickModal: false,
        type: "warning"
      })
        .then(() => {
          this.load();
          api.blindBoxOrderPrizeLogs
            .del(id)
            .then(res => {
              this.unload();
              if (res.data.code === 200) {
                this.$message({
                  type: "success",
                  message: "删除成功!"
                });
                this.logData.data.splice(index, 1);
                this.logData.total--;
              }
            })
            .catch(error => {
              console.log(error);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    // 初始化
    init() {
      this.editParams = {
        name: "",
        image: "",
        sort: "",
        price: "",
        three_price: "",
        five_price: "",
        cat_id: "",
        probability: [
          {name: "尊贵", level_id: 1},
          {name: "稀有", level_id: 2},
          {name: "史诗", level_id: 3},
          {name: "传说", level_id: 4}
        ]
      };
      this.back();
      this.getData();
    },
    // 改变每页条数时
    changeSize(limit) {
      this.searchParams.limit = limit;
      this.getData();
    },
    // 改变当前页码时
    changePage(page) {
      this.searchParams.page = page;
      this.getData();
    },
    add() {
      this.status = "add";
    },
    // 添加页面
    detail(id) {
      this.load();
      api.wealRoom
        .show(id)
        .then(res => {
          if (res.data.code === 200) {
            this.unload();
            this.status = "edit";
            this.editParams = res.data.data;
          }
        })
        .catch(error => {
          console.log(error);
        });
    }
  }
};
</script>

<style scoped lang="less">
.demo-table-expand {
  font-size: 0;
}

.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}

.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>
